home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d13
/
phantz.arc
/
PHANT4.Z
/
PHANT4
Wrap
Text File
|
1991-06-06
|
60KB
|
2,208 lines
: ---------CUT HERE---------
: This is a shar archive. Extract with sh, not csh.
: The rest of this file will extract:
: macros.h phantdefs.h setup.c misc.c oldplayer.h
echo x - macros.h
sed 's/^X//' > macros.h << '!EOR!'
X/*
X * macros.h - macro definitions for Phantasia
X */
X
X#define ROLL(BASE,INTERVAL) floor((BASE) + (INTERVAL) * random())
X#define SGN(X) ((X) < 0 ? -1 : 1)
X#define CIRCLE(X, Y) floor(distance(X, 0.0, Y, 0.0) / 125.0 + 1)
X#define MAX(A, B) ((A) > (B) ? (A) : (B))
X#define MIN(A, B) ((A) < (B) ? (A) : (B))
X#define ILLCMD() mvaddstr(5, 0, Illcmd)
X#define MAXMOVE() (Player.p_level * 1.5 + 1)
X#define ILLMOVE() mvaddstr(5, 0, Illmove)
X#define ILLSPELL() mvaddstr(5, 0, Illspell)
X#define NOMANA() mvaddstr(5, 0, Nomana)
X#define SOMEBETTER() addstr(Somebetter)
X#define NOBETTER() mvaddstr(17, 0, Nobetter)
!EOR!
echo x - phantdefs.h
sed 's/^X//' > phantdefs.h << '!EOR!'
X/*
X * phantdefs.h - important constants for Phantasia
X */
X
X/* ring constants */
X#define R_NONE 0 /* no ring */
X#define R_NAZREG 1 /* regular Nazgul ring (expires) */
X#define R_DLREG 2 /* regular Dark Lord ring (does not expire) */
X#define R_BAD 3 /* bad ring */
X#define R_SPOILED 4 /* ring which has gone bad */
X
X/* status constants */
X#define S_NOTUSED 0 /* record not in use */
X#define S_OFF 1 /* not playing */
X#define S_PLAYING 2 /* playing - nothing else */
X#define S_CLOAKED 3 /* playing - cloaked */
X#define S_INBATTLE 4 /* playing - in battle */
X#define S_MONSTER 5 /* playing - fighting monster */
X#define S_TRADING 6 /* playing - at a trading post */
X#define S_HUNGUP 7 /* error occured with character */
X
X/* tampered constants */
X#define T_OFF 0 /* nothing */
X#define T_NRGVOID 1 /* hit an energy void */
X#define T_GRAIL 2 /* landed on the holy grail */
X#define T_TRANSPORT 3 /* transported by king */
X#define T_BESTOW 4 /* gold bestowed by king */
X#define T_CURSED 5 /* cursed by king */
X#define T_MONSTER 6 /* monster lobbed by valar */
X#define T_BLESSED 7 /* blessed by valar */
X#define T_RELOCATE 8 /* moved by valar */
X#define T_HEAL 9 /* healed by valar */
X#define T_VAPORIZED 10 /* vaporized by wizard */
X#define T_EXVALAR 11 /* no longer valar */
X
X/* inter-terminal battle status constants */
X#define I_OFF 0 /* nothing */
X#define I_RAN 1 /* ran away */
X#define I_STUCK 2 /* tried to run unsuccessfully */
X#define I_BLEWIT 3 /* tried to luckout unsuccessfully */
X#define I_KILLED 4 /* killed foe */
X
X/* constants for altering coordinates */
X#define A_SPECIFIC 0 /* coordinates specified */
X#define A_FORCED 1 /* coordinates specified, ignore Beyond */
X#define A_NEAR 2 /* coordinates not specified, move near */
X#define A_FAR 3 /* coordinates not specified, move far */
X
X/* constants for character types */
X#define C_MAGIC 0 /* magic user */
X#define C_FIGHTER 1 /* fighter */
X#define C_ELF 2 /* elf */
X#define C_DWARF 3 /* dwarf */
X#define C_HALFLING 4 /* halfling */
X#define C_EXPER 5 /* experimento */
X#define C_SUPER 6 /* super being */
X
X/* constants for special character types */
X#define SC_NONE 0 /* not a special character */
X#define SC_KING 1 /* king */
X#define SC_COUNCIL 2 /* council of the wise */
X#define SC_VALAR 3 /* valar */
X#define SC_EXVALAR 4 /* ex-valar */
X
X/* special monster constants */
X#define SM_NONE 0 /* nothing special */
X#define SM_UNICORN 1 /* unicorn */
X#define SM_MODNAR 2 /* Modnar */
X#define SM_MIMIC 3 /* mimic */
X#define SM_DARKLORD 4 /* Dark Lord */
X#define SM_LEANAN 5 /* Leanan-Sidhe */
X#define SM_SARUMAN 6 /* Saruman */
X#define SM_THAUMATURG 7 /* thaumaturgist */
X#define SM_BALROG 8 /* balrog */
X#define SM_VORTEX 9 /* vortex */
X#define SM_NAZGUL 10 /* nazgul */
X#define SM_TIAMAT 11 /* Tiamat */
X#define SM_KOBOLD 12 /* kobold */
X#define SM_SHELOB 13 /* Shelob */
X#define SM_FAERIES 14 /* assorted faeries */
X#define SM_LAMPREY 15 /* lamprey */
X#define SM_SHRIEKER 16 /* shrieker */
X#define SM_BONNACON 17 /* bonnacon */
X#define SM_SMEAGOL 18 /* Smeagol */
X#define SM_SUCCUBUS 19 /* succubus */
X#define SM_CERBERUS 20 /* Cerberus */
X#define SM_UNGOLIANT 21 /* Ungoliant */
X#define SM_JABBERWOCK 22 /* jabberwock */
X#define SM_MORGOTH 23 /* Morgoth */
X#define SM_TROLL 24 /* troll */
X#define SM_WRAITH 25 /* wraith */
X
X/* constants for spells */
X#define ML_ALLORNOTHING 0.0 /* magic level for 'all or nothing' */
X#define MM_ALLORNOTHING 1.0 /* mana used for 'all or nothing' */
X#define ML_MAGICBOLT 5.0 /* magic level for 'magic bolt' */
X#define ML_FORCEFIELD 15.0 /* magic level for 'force field' */
X#define MM_FORCEFIELD 30.0 /* mana used for 'force field' */
X#define ML_XFORM 25.0 /* magic level for 'transform' */
X#define MM_XFORM 50.0 /* mana used for 'transform' */
X#define ML_INCRMIGHT 35.0 /* magic level for 'increase might' */
X#define MM_INCRMIGHT 75.0 /* mana used for 'increase might' */
X#define ML_INVISIBLE 45.0 /* magic level for 'invisibility' */
X#define MM_INVISIBLE 90.0 /* mana used for 'invisibility' */
X#define ML_XPORT 60.0 /* magic level for 'transport' */
X#define MM_XPORT 125.0 /* mana used for 'transport' */
X#define ML_PARALYZE 75.0 /* magic level for 'paralyze' */
X#define MM_PARALYZE 150.0 /* mana used for 'paralyze' */
X#define MM_SPECIFY 1000.0 /* mana used for 'specify' */
X#define ML_CLOAK 20.0 /* magic level for 'cloak' */
X#define MEL_CLOAK 7.0 /* experience level for 'cloak' */
X#define MM_CLOAK 35.0 /* mana used for 'cloak' */
X#define ML_TELEPORT 40.0 /* magic level for 'teleport' */
X#define MEL_TELEPORT 12.0 /* experience level for 'teleport' */
X#define MM_INTERVENE 1000.0 /* mana used to 'intervene' */
X
X/* some miscellaneous constants */
X#define SZ_DATABUF 100 /* size of input buffer */
X#define SZ_PLAYERSTRUCT sizeof(struct player) /* size of player structure */
X#define SZ_VOIDSTRUCT sizeof(struct energyvoid) /* size of energy void struct */
X#define SZ_SCORESTRUCT sizeof(struct scoreboard) /* size of score board entry */
X#define SZ_MONSTERSTRUCT sizeof(struct monster) /* size of monster structure */
X#define SZ_NAME 21 /* size of player name (incl. trailing nul) */
X#define SZ_PASSWORD 9 /* size of password (incl. trailing nul) */
X#define SZ_LOGIN 9 /* size of login (incl. trailing nul) */
X
X#define N_DAYSOLD 21 /* number of days old for purge */
X#define N_AGE 500 /* age to degenerate ratio */
X#define N_GEMVALUE (1000.0) /* number of gold pieces to gem ratio */
X#define N_TAXAMOUNT (7.0) /* tax percent */
X#ifdef OK_TO_PLAY
X#define N_MAXUSERS 30 /* max. number of users allowed on system */
X#endif
X
X#define D_BEYOND (1.1e6) /* distance to beyond point of no return */
X#define D_EXPER (2000.0) /* distance experimentos are allowed */
X
X#define CH_MARKDELETE '\001' /* used to alter name of deleted players */
X#define CH_KILL '\030' /* kill character (ctrl-X) */
X#define CH_ERASE '\010' /* erase character (ctrl-H) */
X#define CH_NEWLINE '\n' /* newline */
X#define CH_REDRAW '\014' /* redraw screen character (ctrl-L) */
!EOR!
echo x - setup.c
sed 's/^X//' > setup.c << '!EOR!'
X/*
X * setup.c - set up all files for Phantasia
X */
X#include "include.h"
X#include <sys/types.h>
X#include <sys/stat.h>
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: main()
X/
X/ FUNCTION: setup files for Phantasia 3.3.2
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
X/ fgets(), floor(), srand(), umask(), random(), strcpy(), getuid(),
X/ unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
X/
X/ GLOBAL INPUTS: Peoplefile[], Curmonster, _iob[], Databuf[], *Monstfp,
X/ Lastdead[], Goldfile[], Voidfile[], Motdfile[], Messfile[], Scorefile[],
X/ Enemyfile[], Monstfile[], Enrgyvoid
X/
X/ GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
X/
X/ DESCRIPTION:
X/
X/ This program tries to verify the parameters specified in
X/ the Makefile.
X/
X/ Create all necessary files. Note that nothing needs to be
X/ put in these files.
X/ Also, the monster binary data base is created here.
X/
X/************************************************************************/
X
Xmain()
X{
XFILE *fp; /* for opening files */
Xstruct stat fbuf; /* for getting files statistics */
Xregister char **filename; /* for pointing to file names */
Xregister int fd; /* file descriptor */
Xstatic char *files[] = /* all files to create */
X {
X Monstfile,
X Peoplefile,
X Messfile,
X Lastdead,
X Motdfile,
X Goldfile,
X Voidfile,
X Scorefile,
X#ifdef ENEMY
X Enemyfile,
X#endif
X (char *) NULL
X };
X
X srand((unsigned) time((long *) NULL)); /* prime random numbers */
X
X umask(077); /* only owner can read/write created files */
X
X if (getuid() != UID)
X fprintf(stderr, "Warning: UID (%d) is not equal to current uid.\n", UID);
X
X /* check Phantasia destination directory */
X if (stat(DEST", &fbuf) < 0)
X /* not found */
X {
X Error("Cannot stat %s.\n", DEST");
X exit(1);
X /*NOTREACHED*/
X }
X
X if ((fbuf.st_mode & S_IFDIR) == 0)
X /* not a directory */
X Error("%s is not a directory.\n", DEST");
X /*NOTREACHED*/
X
X /* try to create data files */
X filename = &files[0];
X while (*filename != NULL)
X /* create each file */
X {
X if (stat(*filename, &fbuf) == 0)
X /* file exists; remove it */
X {
X if (*filename == Peoplefile)
X /* do not reset character file if it already exists */
X {
X ++filename;
X continue;
X }
X
X if (unlink(*filename) < 0)
X Error("Cannot unlink %s.\n", *filename);
X /*NOTREACHED*/
X }
X
X if ((fd = creat(*filename, 0600)) < 0)
X Error("Cannot create %s.\n", *filename);
X /*NOTREACHED*/
X
X close(fd); /* close newly created file */
X
X ++filename; /* process next file */
X }
X
X /* put holy grail info into energy void file */
X Enrgyvoid.ev_active = TRUE;
X Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
X Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
X if ((fp = fopen(Voidfile, "w")) == NULL)
X Error("Cannot update %s.\n", Voidfile);
X else
X {
X fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
X fclose(fp);
X }
X
X /* create binary monster data base */
X if ((Monstfp = fopen(Monstfile, "w")) == NULL)
X Error("Cannot update %s.\n", Monstfile);
X else
X {
X if ((fp = fopen("monsters.asc", "r")) == NULL)
X {
X fclose(Monstfp);
X Error("cannot open %s to create monster database.\n", "monsters.asc");
X }
X else
X {
X Curmonster.m_o_strength =
X Curmonster.m_o_speed =
X Curmonster.m_maxspeed =
X Curmonster.m_o_energy =
X Curmonster.m_melee =
X Curmonster.m_skirmish = 0.0;
X
X while (fgets(Databuf, SZ_DATABUF, fp) != NULL)
X /* read in text file, convert to binary */
X {
X sscanf(&Databuf[24], "%F%F%F%F%F%d%d%F",
X &Curmonster.m_strength, &Curmonster.m_brains,
X &Curmonster.m_speed, &Curmonster.m_energy,
X &Curmonster.m_experience, &Curmonster.m_treasuretype,
X &Curmonster.m_type, &Curmonster.m_flock);
X Databuf[24] = '\0';
X strcpy(Curmonster.m_name, Databuf);
X fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
X }
X fclose(fp);
X fclose(Monstfp);
X }
X }
X
X /* write to motd file */
X printf("One line 'motd' ? ");
X if (fgets(Databuf, SZ_DATABUF, stdin) == NULL)
X Databuf[0] = '\0';
X if ((fp = fopen(Motdfile, "w")) == NULL)
X Error("Cannot update %s.\n", Motdfile);
X else
X {
X fwrite(Databuf, sizeof(char), strlen(Databuf), fp);
X fclose(fp);
X }
X
X /* report compile-time options */
X printf("Compiled options:\n\n");
X printf("Phantasia destination directory: %s\n", DEST");
X printf("Wizard: %s UID: %d\n", WIZARD, UID);
X
X#ifdef OK_TO_PLAY
X printf("Restricted playing enabled.\n");
X#else
X printf("Playing unrestricted.\n");
X#endif
X
X#ifdef ENEMY
X printf("Enemy list enabled.\n");
X#else
X printf("Enemy list disabled.\n");
X#endif
X
X#ifdef SHELL
X printf("Shell escapes enabled. Default shell: %s\n", SHELL);
X#else
X printf("Shell escapes disabled.\n");
X#endif
X
X#ifdef BSD41
X printf("Compiled for BSD 4.1\n");
X#endif
X
X#ifdef BSD42
X printf("Compiled for BSD 4.2\n");
X#endif
X
X#ifdef SYS3
X printf("Compiled for System III\n");
X#endif
X
X#ifdef SYS5
X printf("Compiled for System V\n");
X#endif
X
X exit(0);
X /*NOTREACHED*/
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: Error()
X/
X/ FUNCTION: print an error message, and exit
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ char *str - format string for printf()
X/ char *file - file which caused error
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: exit(), perror(), fprintf()
X/
X/ GLOBAL INPUTS: _iob[]
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Print an error message, then exit.
X/
X/************************************************************************/
X
XError(str, file)
Xchar *str, *file;
X{
X fprintf(stderr, "Error: ");
X fprintf(stderr, str, file);
X perror(file);
X exit(1);
X /*NOTREACHED*/
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: random()
X/
X/ FUNCTION: return a random number
X/
X/ AUTHOR: E. A. Estes, 2/7/86
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: rand()
X/
X/ GLOBAL INPUTS: none
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/
X/************************************************************************/
X
Xdouble
Xrandom()
X{
X if (sizeof(int) != 2)
X return((double) (rand() & 0x7fff) / 32768.0);
X else
X return((double) rand() / 32768.0);
X}
!EOR!
echo x - misc.c
sed 's/^X//' > misc.c << '!EOR!'
X/*
X * misc.c Phantasia miscellaneous support routines
X */
X
X#include "include.h"
X
X/************************************************************************
X/
X/ FUNCTION NAME: movelevel()
X/
X/ FUNCTION: move player to new level
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: death(), floor(), wmove(), random(), waddstr(), explevel()
X/
X/ GLOBAL INPUTS: Player, *stdscr, *Statptr, Stattable[]
X/
X/ GLOBAL OUTPUTS: Player, Changed
X/
X/ DESCRIPTION:
X/ Use lookup table to increment important statistics when
X/ progressing to new experience level.
X/ Players are rested to maximum as a bonus for making a new
X/ level.
X/ Check for council of wise, and being too big to be king.
X/
X/************************************************************************/
X
Xmovelevel()
X{
Xregister struct charstats *statptr; /* for pointing into Stattable */
Xdouble new; /* new level */
Xdouble inc; /* increment between new and old levels */
X
X Changed = TRUE;
X
X if (Player.p_type == C_EXPER)
X /* roll a type to use for increment */
X statptr = &Stattable[(int) ROLL(C_MAGIC, C_HALFLING - C_MAGIC + 1)];
X else
X statptr = Statptr;
X
X new = explevel(Player.p_experience);
X inc = new - Player.p_level;
X Player.p_level = new;
X
X /* add increments to statistics */
X Player.p_strength += statptr->c_strength.increase * inc;
X Player.p_mana += statptr->c_mana.increase * inc;
X Player.p_brains += statptr->c_brains.increase * inc;
X Player.p_magiclvl += statptr->c_magiclvl.increase * inc;
X Player.p_maxenergy += statptr->c_energy.increase * inc;
X
X /* rest to maximum upon reaching new level */
X Player.p_energy = Player.p_maxenergy + Player.p_shield;
X
X if (Player.p_crowns > 0 && Player.p_level >= 1000.0)
X /* no longer able to be king -- turn crowns into cash */
X {
X Player.p_gold += ((double) Player.p_crowns) * 5000.0;
X Player.p_crowns = 0;
X }
X
X if (Player.p_level >= 3000.0 && Player.p_specialtype < SC_COUNCIL)
X /* make a member of the council */
X {
X mvaddstr(6, 0, "You have made it to the Council of the Wise.\n");
X addstr("Good Luck on your search for the Holy Grail.\n");
X
X Player.p_specialtype = SC_COUNCIL;
X
X /* no rings for council and above */
X Player.p_ring.ring_type = R_NONE;
X Player.p_ring.ring_duration = 0;
X
X Player.p_lives = 3; /* three extra lives */
X }
X
X if (Player.p_level > 9999.0 && Player.p_specialtype != SC_VALAR)
X death("Old age");
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: descrlocation()
X/
X/ FUNCTION: return a formatted description of location
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ struct player playerp - pointer to player structure
X/ bool shortflag - set if short form is desired
X/
X/ RETURN VALUE: pointer to string containing result
X/
X/ MODULES CALLED: fabs(), floor(), sprintf(), distance()
X/
X/ GLOBAL INPUTS: Databuf[]
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Look at coordinates and return an appropriately formatted
X/ string.
X/
X/************************************************************************/
X
Xchar *
Xdescrlocation(playerp, shortflag)
Xstruct player *playerp;
Xbool shortflag;
X{
Xdouble circle; /* corresponding circle for coordinates */
Xregister int quadrant; /* quandrant of grid */
Xregister char *label; /* pointer to place name */
Xstatic char *nametable[4][4] = /* names of places */
X {
X "Anorien", "Ithilien", "Rohan", "Lorien",
X "Gondor", "Mordor", "Dunland", "Rovanion",
X "South Gondor", "Khand", "Eriador", "The Iron Hills",
X "Far Harad", "Near Harad", "The Northern Waste", "Rhun"
X };
X
X if (playerp->p_specialtype == SC_VALAR)
X return(" is in Valhala");
X else if ((circle = CIRCLE(playerp->p_x, playerp->p_y)) >= 1000.0)
X {
X if (MAX(fabs(playerp->p_x), fabs(playerp->p_y)) > D_BEYOND)
X label = "The Point of No Return";
X else
X label = "The Ashen Mountains";
X }
X else if (circle >= 55)
X label = "Morannon";
X else if (circle >= 35)
X label = "Kennaquahair";
X else if (circle >= 20)
X label = "The Dead Marshes";
X else if (circle >= 9)
X label = "The Outer Waste";
X else if (circle >= 5)
X label = "The Moors Adventurous";
X else
X {
X if (playerp->p_x == 0.0 && playerp->p_y == 0.0)
X label = "The Lord's Chamber";
X else
X {
X /* this expression is split to prevent compiler loop with some compilers */
X quadrant = ((playerp->p_x > 0.0) ? 1 : 0);
X quadrant += ((playerp->p_y >= 0.0) ? 2 : 0);
X label = nametable[((int) circle) - 1][quadrant];
X }
X }
X
X if (shortflag)
X sprintf(Databuf, "%.29s", label);
X else
X sprintf(Databuf, " is in %s (%.0f,%.0f)", label, playerp->p_x, playerp->p_y);
X
X return(Databuf);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: tradingpost()
X/
X/ FUNCTION: do trading post stuff
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: writerecord(), adjuststats(), fabs(), more(), sqrt(),
X/ sleep(), floor(), wmove(), random(), wclear(), printw(),
X/ altercoordinates(), infloat(), waddstr(), wrefresh(), mvprintw(), getanswer(),
X/ wclrtoeol(), wclrtobot()
X/
X/ GLOBAL INPUTS: Menu[], Circle, Player, *stdscr, Fileloc, Nobetter[]
X/
X/ GLOBAL OUTPUTS: Player
X/
X/ DESCRIPTION:
X/ Different trading posts have different items.
X/ Merchants cannot be cheated, but they can be dishonest
X/ themselves.
X/
X/ Shields, swords, and quicksilver are not cumulative. This is
X/ one major area of complaint, but there are two reasons for this:
X/ 1) It becomes MUCH too easy to make very large versions
X/ of these items.
X/ 2) In the real world, one cannot simply weld two swords
X/ together to make a bigger one.
X/
X/ At one time, it was possible to sell old weapons at half the purchase
X/ price. This resulted in huge amounts of gold floating around,
X/ and the game lost much of its challenge.
X/
X/ Also, purchasing gems defeats the whole purpose of gold. Gold
X/ is small change for lower level players. They really shouldn't
X/ be able to accumulate more than enough gold for a small sword or
X/ a few books. Higher level players shouldn't even bother to pick
X/ up gold, except maybe to buy mana once in a while.
X/
X/************************************************************************/
X
Xtradingpost()
X{
Xdouble numitems; /* number of items to purchase */
Xdouble cost; /* cost of purchase */
Xdouble blessingcost; /* cost of blessing */
Xint ch; /* input */
Xregister int size; /* size of the trading post */
Xregister int loop; /* loop counter */
Xint cheat = 0; /* number of times player has tried to cheat */
Xbool dishonest = FALSE;/* set when merchant is dishonest */
X
X Player.p_status = S_TRADING;
X writerecord(&Player, Fileloc);
X
X clear();
X addstr("You are at a trading post. All purchases must be made with gold.");
X
X size = sqrt(fabs(Player.p_x / 100)) + 1;
X size = MIN(7, size);
X
X /* set up cost of blessing */
X blessingcost = 1000.0 * (Player.p_level + 5.0);
X
X /* print Menu */
X move(7, 0);
X for (loop = 0; loop < size; ++loop)
X /* print Menu */
X {
X if (loop == 6)
X cost = blessingcost;
X else
X cost = Menu[loop].cost;
X printw("(%d) %-12s: %6.0f\n", loop + 1, Menu[loop].item, cost);
X }
X
X mvprintw(5, 0, "L:Leave P:Purchase S:Sell Gems ? ");
X
X for (;;)
X {
X adjuststats(); /* truncate any bad values */
X
X /* print some important statistics */
X mvprintw(1, 0, "Gold: %9.0f Gems: %9.0f Level: %6.0f Charms: %6d\n",
X Player.p_gold, Player.p_gems, Player.p_level, Player.p_charms);
X printw("Shield: %9.0f Sword: %9.0f Quicksilver:%3.0f Blessed: %s\n",
X Player.p_shield, Player.p_sword, Player.p_quksilver,
X (Player.p_blessing ? " True" : "False"));
X printw("Brains: %9.0f Mana: %9.0f", Player.p_brains, Player.p_mana);
X
X move(5, 36);
X ch = getanswer("LPS", FALSE);
X move(15, 0);
X clrtobot();
X switch(ch)
X {
X case 'L': /* leave */
X case '\n':
X altercoordinates(0.0, 0.0, A_NEAR);
X return;
X
X case 'P': /* make purchase */
X mvaddstr(15, 0, "What what would you like to buy ? ");
X ch = getanswer(" 1234567", FALSE);
X move(15, 0);
X clrtoeol();
X
X if (ch - '0' > size)
X addstr("Sorry, this merchant doesn't have that.");
X else
X switch (ch)
X {
X case '1':
X printw("Mana is one per %.0f gold piece. How many do you want (%.0f max) ? ",
X Menu[0].cost, floor(Player.p_gold / Menu[0].cost));
X cost = (numitems = floor(infloat())) * Menu[0].cost;
X
X if (cost > Player.p_gold || numitems < 0)
X ++cheat;
X else
X {
X Player.p_gold -= cost;
X if (random() < 0.02)
X dishonest = TRUE;
X else
X Player.p_mana += numitems;
X }
X break;
X
X case '2':
X printw("Shields are %.0f per +1. How many do you want (%.0f max) ? ",
X Menu[1].cost, floor(Player.p_gold / Menu[1].cost));
X cost = (numitems = floor(infloat())) * Menu[1].cost;
X
X if (numitems == 0.0)
X break;
X else if (cost > Player.p_gold || numitems < 0)
X ++cheat;
X else if (numitems < Player.p_shield)
X NOBETTER();
X else
X {
X Player.p_gold -= cost;
X if (random() < 0.02)
X dishonest = TRUE;
X else
X Player.p_shield = numitems;
X }
X break;
X
X case '3':
X printw("A book costs %.0f gp. How many do you want (%.0f max) ? ",
X Menu[2].cost, floor(Player.p_gold / Menu[2].cost));
X cost = (numitems = floor(infloat())) * Menu[2].cost;
X
X if (cost > Player.p_gold || numitems < 0)
X ++cheat;
X else
X {
X Player.p_gold -= cost;
X if (random() < 0.02)
X dishonest = TRUE;
X else if (random() * numitems > Player.p_level / 10.0
X && numitems != 1)
X {
X printw("\nYou blew your mind!\n");
X Player.p_brains /= 5;
X }
X else
X Player.p_brains += floor(numitems) * ROLL(20, 8);
X }
X break;
X
X case '4':
X printw("Swords are %.0f gp per +1. How many + do you want (%.0f max) ? ",
X Menu[3].cost, floor(Player.p_gold / Menu[3].cost));
X cost = (numitems = floor(infloat())) * Menu[3].cost;
X
X if (numitems == 0.0)
X break;
X else if (cost > Player.p_gold || numitems < 0)
X ++cheat;
X else if (numitems < Player.p_sword)
X NOBETTER();
X else
X {
X Player.p_gold -= cost;
X if (random() < 0.02)
X dishonest = TRUE;
X else
X Player.p_sword = numitems;
X }
X break;
X
X case '5':
X printw("A charm costs %.0f gp. How many do you want (%.0f max) ? ",
X Menu[4].cost, floor(Player.p_gold / Menu[4].cost));
X cost = (numitems = floor(infloat())) * Menu[4].cost;
X
X if (cost > Player.p_gold || numitems < 0)
X ++cheat;
X else
X {
X Player.p_gold -= cost;
X if (random() < 0.02)
X dishonest = TRUE;
X else
X Player.p_charms += numitems;
X }
X break;
X
X case '6':
X printw("Quicksilver is %.0f gp per +1. How many + do you want (%.0f max) ? ",
X Menu[5].cost, floor(Player.p_gold / Menu[5].cost));
X cost = (numitems = floor(infloat())) * Menu[5].cost;
X
X if (numitems == 0.0)
X break;
X else if (cost > Player.p_gold || numitems < 0)
X ++cheat;
X else if (numitems < Player.p_quksilver)
X NOBETTER();
X else
X {
X Player.p_gold -= cost;
X if (random() < 0.02)
X dishonest = TRUE;
X else
X Player.p_quksilver = numitems;
X }
X break;
X
X case '7':
X if (Player.p_blessing)
X {
X addstr("You already have a blessing.");
X break;
X }
X
X printw("A blessing requires a %.0f gp donation. Still want one ? ", blessingcost);
X ch = getanswer("NY", FALSE);
X
X if (ch == 'Y')
X if (Player.p_gold < blessingcost)
X ++cheat;
X else
X {
X Player.p_gold -= blessingcost;
X if (random() < 0.02)
X dishonest = TRUE;
X else
X Player.p_blessing = TRUE;
X }
X break;
X }
X break;
X
X case 'S': /* sell gems */
X mvprintw(15, 0, "A gem is worth %.0f gp. How many do you want to sell (%.0f max) ? ",
X (double) N_GEMVALUE, Player.p_gems);
X numitems = floor(infloat());
X
X if (numitems > Player.p_gems || numitems < 0)
X ++cheat;
X else
X {
X Player.p_gems -= numitems;
X Player.p_gold += numitems * N_GEMVALUE;
X }
X }
X
X if (cheat == 1)
X mvaddstr(17, 0, "Come on, merchants aren't stupid. Stop cheating.\n");
X else if (cheat == 2)
X {
X mvaddstr(17, 0, "You had your chance. This merchant happens to be\n");
X printw("a %.0f level magic user, and you made %s mad!\n",
X ROLL(Circle * 20.0, 40.0), (random() < 0.5) ? "him" : "her");
X altercoordinates(0.0, 0.0, A_FAR);
X Player.p_energy /= 2.0;
X ++Player.p_sin;
X more(23);
X return;
X }
X else if (dishonest)
X {
X mvaddstr(17, 0, "The merchant stole your money!");
X refresh();
X altercoordinates(Player.p_x - Player.p_x / 10.0,
X Player.p_y - Player.p_y / 10.0, A_SPECIFIC);
X sleep(2);
X return;
X }
X }
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: displaystats()
X/
X/ FUNCTION: print out important player statistics
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: descrstatus(), descrlocation(), mvprintw()
X/
X/ GLOBAL INPUTS: Users, Player
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Important player statistics are printed on the screen.
X/
X/************************************************************************/
X
Xdisplaystats()
X{
X mvprintw(0, 0, "%s%s\n", Player.p_name, descrlocation(&Player, FALSE));
X mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n",
X Player.p_level, Player.p_energy, Player.p_maxenergy + Player.p_shield,
X Player.p_mana, Users);
X mvprintw(2, 0, "Quick :%3.0f(%3.0f) Strength:%9.0f(%9.0f) Gold :%9.0f %s\n",
X Player.p_speed, Player.p_quickness + Player.p_quksilver, Player.p_might,
X Player.p_strength + Player.p_sword, Player.p_gold, descrstatus(&Player));
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: allstatslist()
X/
X/ FUNCTION: show player items
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: mvprintw(), descrtype()
X/
X/ GLOBAL INPUTS: Player
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Print out some player statistics of lesser importance.
X/
X/************************************************************************/
X
Xallstatslist()
X{
Xstatic char *flags[] = /* to print value of some bools */
X {
X "False",
X " True"
X };
X
X mvprintw( 8, 0, "Type: %s\n", descrtype(&Player, FALSE));
X
X mvprintw(10, 0, "Experience: %9.0f", Player.p_experience);
X mvprintw(11, 0, "Brains : %9.0f", Player.p_brains);
X mvprintw(12, 0, "Magic Lvl : %9.0f", Player.p_magiclvl);
X mvprintw(13, 0, "Sin : %9.5f", Player.p_sin);
X mvprintw(14, 0, "Poison : %9.5f", Player.p_poison);
X mvprintw(15, 0, "Gems : %9.0f", Player.p_gems);
X mvprintw(16, 0, "Age : %9d", Player.p_age);
X mvprintw(10, 40, "Holy Water: %9d", Player.p_holywater);
X mvprintw(11, 40, "Amulets : %9d", Player.p_amulets);
X mvprintw(12, 40, "Charms : %9d", Player.p_charms);
X mvprintw(13, 40, "Crowns : %9d", Player.p_crowns);
X mvprintw(14, 40, "Shield : %9.0f", Player.p_shield);
X mvprintw(15, 40, "Sword : %9.0f", Player.p_sword);
X mvprintw(16, 40, "Quickslver: %9.0f", Player.p_quksilver);
X
X mvprintw(18, 0, "Blessing: %s Ring: %s Virgin: %s Palantir: %s",
X flags[Player.p_blessing], flags[Player.p_ring.ring_type != R_NONE],
X flags[Player.p_virgin], flags[Player.p_palantir]);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: descrtype()
X/
X/ FUNCTION: return a string specifying player type
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ struct player playerp - pointer to structure for player
X/ bool shortflag - set if short form is desired
X/
X/ RETURN VALUE: pointer to string describing player type
X/
X/ MODULES CALLED: strcpy()
X/
X/ GLOBAL INPUTS: Databuf[]
X/
X/ GLOBAL OUTPUTS: Databuf[]
X/
X/ DESCRIPTION:
X/ Return a string describing the player type.
X/ King, council, valar, supercedes other types.
X/ The first character of the string is '*' if the player
X/ has a crown.
X/ If 'shortflag' is TRUE, return a 3 character string.
X/
X/************************************************************************/
X
Xchar *
Xdescrtype(playerp, shortflag)
Xstruct player *playerp;
Xbool shortflag;
X{
Xregister int type; /* for caluculating result subscript */
Xstatic char *results[] = /* description table */
X {
X " Magic User", " MU",
X " Fighter", " F ",
X " Elf", " E ",
X " Dwarf", " D ",
X " Halfling", " H ",
X " Experimento", " EX",
X " Super", " S ",
X " King", " K ",
X " Council of Wise", " CW",
X " Ex-Valar", " EV",
X " Valar", " V ",
X " ? ", " ? "
X };
X
X type = playerp->p_type;
X
X switch (playerp->p_specialtype)
X {
X case SC_NONE:
X type = playerp->p_type;
X break;
X
X case SC_KING:
X type = 7;
X break;
X
X case SC_COUNCIL:
X type = 8;
X break;
X
X case SC_EXVALAR:
X type = 9;
X break;
X
X case SC_VALAR:
X type = 10;
X break;
X }
X
X type *= 2; /* calculate offset */
X
X if (type > 20)
X /* error */
X type = 22;
X
X if (shortflag)
X /* use short descriptions */
X ++type;
X
X if (playerp->p_crowns > 0)
X {
X strcpy(Databuf, results[type]);
X Databuf[0] = '*';
X return(Databuf);
X }
X else
X return(results[type]);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: findname()
X/
X/ FUNCTION: find location in player file of given name
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ char *name - name of character to look for
X/ struct player *playerp - pointer of structure to fill
X/
X/ RETURN VALUE: location of player if found, -1 otherwise
X/
X/ MODULES CALLED: fread(), fseek(), strcmp()
X/
X/ GLOBAL INPUTS: Wizard, *Playersfp
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Search the player file for the player of the given name.
X/ If player is found, fill structure with player data.
X/
X/************************************************************************/
X
Xlong
Xfindname(name, playerp)
Xregister char *name;
Xregister struct player *playerp;
X{
Xlong loc = 0; /* location in the file */
X
X fseek(Playersfp, 0L, 0);
X while (fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
X {
X if (strcmp(playerp->p_name, name) == 0)
X {
X if (playerp->p_status != S_NOTUSED || Wizard)
X /* found it */
X return(loc);
X }
X loc += SZ_PLAYERSTRUCT;
X }
X
X return(-1);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: allocrecord()
X/
X/ FUNCTION: find space in the player file for a new character
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: location of free space in file
X/
X/ MODULES CALLED: initplayer(), writerecord(), fread(), fseek()
X/
X/ GLOBAL INPUTS: Other, *Playersfp
X/
X/ GLOBAL OUTPUTS: Player
X/
X/ DESCRIPTION:
X/ Search the player file for an unused entry. If none are found,
X/ make one at the end of the file.
X/
X/************************************************************************/
X
Xlong
Xallocrecord()
X{
Xlong loc = 0L; /* location in file */
X
X fseek(Playersfp, 0L, 0);
X while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
X {
X if (Other.p_status == S_NOTUSED)
X /* found an empty record */
X return(loc);
X else
X loc += SZ_PLAYERSTRUCT;
X }
X
X /* make a new record */
X initplayer(&Other);
X Player.p_status = S_OFF;
X writerecord(&Other, loc);
X
X return(loc);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: freerecord()
X/
X/ FUNCTION: free up a record on the player file
X/
X/ AUTHOR: E. A. Estes, 2/7/86
X/
X/ ARGUMENTS:
X/ struct player playerp - pointer to structure to free
X/ long loc - location in file to free
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: writerecord()
X/
X/ GLOBAL INPUTS: none
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Mark structure as not used, and update player file.
X/
X/************************************************************************/
X
Xfreerecord(playerp, loc)
Xstruct player *playerp;
Xlong loc;
X{
X playerp->p_name[0] = CH_MARKDELETE;
X playerp->p_status = S_NOTUSED;
X writerecord(playerp, loc);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: leavegame()
X/
X/ FUNCTION: leave game
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: freerecord(), writerecord(), cleanup()
X/
X/ GLOBAL INPUTS: Player, Fileloc
X/
X/ GLOBAL OUTPUTS: Player
X/
X/ DESCRIPTION:
X/ Mark player as inactive, and cleanup.
X/ Do not save players below level 1.
X/
X/************************************************************************/
X
Xleavegame()
X{
X
X if (Player.p_level < 1.0)
X /* delete character */
X freerecord(&Player, Fileloc);
X else
X {
X Player.p_status = S_OFF;
X writerecord(&Player, Fileloc);
X }
X
X cleanup(TRUE);
X /*NOTREACHED*/
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: death()
X/
X/ FUNCTION: death routine
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ char *how - pointer to string describing cause of death
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: freerecord(), enterscore(), more(), exit(), fread(),
X/ fseek(), execl(), fopen(), floor(), wmove(), random(), wclear(), strcmp(),
X/ fwrite(), fflush(), printw(), strcpy(), fclose(), waddstr(), cleanup(),
X/ fprintf(), wrefresh(), getanswer(), descrtype()
X/
X/ GLOBAL INPUTS: Curmonster, Wizard, Player, *stdscr, Fileloc, *Monstfp,
X/ Lastdead[], Gameprog[], Messfile[]
X/
X/ GLOBAL OUTPUTS: Player
X/
X/ DESCRIPTION:
X/ Kill off current player.
X/ Handle rings, and multiple lives.
X/ Print an appropriate message.
X/ Update scoreboard, lastdead, and let other players know about
X/ the demise of their comrade.
X/
X/************************************************************************/
X
Xdeath(how)
Xchar *how;
X{
XFILE *fp; /* for updating various files */
Xint ch; /* input */
Xstatic char *deathmesg[] =
X /* add more messages here, if desired */
X {
X "You have been wounded beyond repair. ",
X "You have been disemboweled. ",
X "You've been mashed, mauled, and spit upon. (You're dead.)\n",
X "You died! ",
X "You're a complete failure -- you've died!!\n",
X "You have been dealt a fatal blow! "
X };
X
X clear();
X
X if (strcmp(how, "Stupidity") != 0)
X {
X if (Player.p_level > 9999.0)
X /* old age */
X addstr("Characters must be retired upon reaching level 10000. Sorry.");
X else if (Player.p_lives > 0)
X /* extra lives */
X {
X addstr("You should be more cautious. You've been killed.\n");
X printw("You only have %d more chance(s).\n", --Player.p_lives);
X more(3);
X Player.p_energy = Player.p_maxenergy;
X return;
X }
X else if (Player.p_specialtype == SC_VALAR)
X {
X addstr("You had your chances, but Valar aren't totally\n");
X addstr("immortal. You are now left to wither and die . . .\n");
X more(3);
X Player.p_brains = Player.p_level / 25.0;
X Player.p_energy = Player.p_maxenergy /= 5.0;
X Player.p_quksilver = Player.p_sword = 0.0;
X Player.p_specialtype = SC_COUNCIL;
X return;
X }
X else if (Player.p_ring.ring_inuse &&
X (Player.p_ring.ring_type == R_DLREG || Player.p_ring.ring_type == R_NAZREG))
X /* good ring in use - saved from death */
X {
X mvaddstr(4, 0, "Your ring saved you from death!\n");
X refresh();
X Player.p_ring.ring_type = R_NONE;
X Player.p_energy = Player.p_maxenergy / 12.0 + 1.0;
X if (Player.p_crowns > 0)
X --Player.p_crowns;
X return;
X }
X else if (Player.p_ring.ring_type == R_BAD
X || Player.p_ring.ring_type == R_SPOILED)
X /* bad ring in possession; name idiot after player */
X {
X mvaddstr(4, 0,
X "Your ring has taken control of you and turned you into a monster!\n");
X fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, 0);
X fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
X strcpy(Curmonster.m_name, Player.p_name);
X fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, 0);
X fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
X fflush(Monstfp);
X }
X }
X
X enterscore(); /* update score board */
X
X /* put info in last dead file */
X fp = fopen(Lastdead, "w");
X fprintf(fp,"%s (%s, run by %s, level %.0f, killed by %s)",
X Player.p_name, descrtype(&Player, TRUE),
X Player.p_login, Player.p_level, how);
X fclose(fp);
X
X /* let other players know */
X fp = fopen(Messfile, "w");
X fprintf(fp, "%s was killed by %s.", Player.p_name, how);
X fclose(fp);
X
X freerecord(&Player, Fileloc);
X
X clear();
X move(10, 0);
X addstr(deathmesg[(int) ROLL(0.0, (double) sizeof(deathmesg) / sizeof(char *))]);
X addstr("Care to give it another try ? ");
X ch = getanswer("NY", FALSE);
X
X if (ch == 'Y')
X {
X cleanup(FALSE);
X execl(Gameprog, "phantasia", "-s", (Wizard ? "-S": (char *) NULL), 0);
X exit(0);
X /*NOTREACHED*/
X }
X
X cleanup(TRUE);
X /*NOTREACHED*/
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: writerecord()
X/
X/ FUNCTION: update structure in player file
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ struct player *playerp - pointer to structure to write out
X/ long place - location in file to updata
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: fseek(), fwrite(), fflush()
X/
X/ GLOBAL INPUTS: *Playersfp
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Update location in player file with given structure.
X/
X/************************************************************************/
X
Xwriterecord(playerp, place)
Xregister struct player *playerp;
Xlong place;
X{
X fseek(Playersfp, place, 0);
X fwrite((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);
X fflush(Playersfp);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: explevel()
X/
X/ FUNCTION: calculate level based upon experience
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ double experience - experience to calculate experience level from
X/
X/ RETURN VALUE: experience level
X/
X/ MODULES CALLED: pow(), floor()
X/
X/ GLOBAL INPUTS: none
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Experience level is a geometric progression. This has been finely
X/ tuned over the years, and probably should not be changed.
X/
X/************************************************************************/
X
Xdouble
Xexplevel(experience)
Xdouble experience;
X{
X if (experience < 1.1e7)
X return(floor(pow((experience / 1000.0), 0.4875)));
X else
X return(floor(pow((experience / 1250.0), 0.4865)));
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: truncstring()
X/
X/ FUNCTION: truncate trailing blanks off a string
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ char *string - pointer to null terminated string
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: strlen()
X/
X/ GLOBAL INPUTS: none
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Put nul characters in place of spaces at the end of the string.
X/
X/************************************************************************/
X
Xtruncstring(string)
Xregister char *string;
X{
Xregister int length; /* length of string */
X
X length = strlen(string);
X while (string[--length] == ' ')
X string[length] = '\0';
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: altercoordinates()
X/
X/ FUNCTION: Alter x, y coordinates and set/check location flags
X/
X/ AUTHOR: E. A. Estes, 12/16/85
X/
X/ ARGUMENTS:
X/ double xnew, ynew - new x, y coordinates
X/ int operation - operation to perform with coordinates
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: fabs(), floor(), random(), distance()
X/
X/ GLOBAL INPUTS: Circle, Beyond, Player
X/
X/ GLOBAL OUTPUTS: Marsh, Circle, Beyond, Throne, Player, Changed
X/
X/ DESCRIPTION:
X/ This module is called whenever the player's coordinates are altered.
X/ If the player is beyond the point of no return, he/she is forced
X/ to stay there.
X/
X/************************************************************************/
X
Xaltercoordinates(xnew, ynew, operation)
Xdouble xnew;
Xdouble ynew;
Xint operation;
X{
X switch (operation)
X {
X case A_FORCED: /* move with no checks */
X break;
X
X case A_NEAR: /* pick random coordinates near */
X xnew = Player.p_x + ROLL(1.0, 5.0);
X ynew = Player.p_y - ROLL(1.0, 5.0);
X /* fall through for check */
X
X case A_SPECIFIC: /* just move player */
X if (Beyond && fabs(xnew) < D_BEYOND && fabs(ynew) < D_BEYOND)
X /*
X * cannot move back from point of no return
X * pick the largest coordinate to remain unchanged
X */
X {
X if (fabs(xnew) > fabs(ynew))
X xnew = SGN(Player.p_x) * MAX(fabs(Player.p_x), D_BEYOND);
X else
X ynew = SGN(Player.p_y) * MAX(fabs(Player.p_y), D_BEYOND);
X }
X break;
X
X case A_FAR: /* pick random coordinates far */
X xnew = Player.p_x + SGN(Player.p_x) * ROLL(50 * Circle, 250 * Circle);
X ynew = Player.p_y + SGN(Player.p_y) * ROLL(50 * Circle, 250 * Circle);
X break;
X }
X
X /* now set location flags and adjust coordinates */
X Circle = CIRCLE(Player.p_x = floor(xnew), Player.p_y = floor(ynew));
X
X /* set up flags based upon location */
X Throne = Marsh = Beyond = FALSE;
X
X if (Player.p_x == 0.0 && Player.p_y == 0.0)
X Throne = TRUE;
X else if (Circle < 35 && Circle >= 20)
X Marsh = TRUE;
X else if (MAX(fabs(Player.p_x), fabs(Player.p_y)) >= D_BEYOND)
X Beyond = TRUE;
X
X Changed = TRUE;
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: readrecord()
X/
X/ FUNCTION: read a player structure from file
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ struct player *playerp - pointer to structure to fill
X/ int loc - location of record to read
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: fread(), fseek()
X/
X/ GLOBAL INPUTS: *Playersfp
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Read structure information from player file.
X/
X/************************************************************************/
X
Xreadrecord(playerp, loc)
Xregister struct player *playerp;
Xlong loc;
X{
X fseek(Playersfp, loc, 0);
X fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: adjuststats()
X/
X/ FUNCTION: adjust player statistics
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: death(), floor(), random(), explevel(), movelevel()
X/
X/ GLOBAL INPUTS: Player, *Statptr
X/
X/ GLOBAL OUTPUTS: Circle, Player, Timeout
X/
X/ DESCRIPTION:
X/ Handle adjustment and maximums on various player characteristics.
X/
X/************************************************************************/
X
Xadjuststats()
X{
Xdouble dtemp; /* for temporary calculations */
X
X if (explevel(Player.p_experience) > Player.p_level)
X /* move one or more levels */
X {
X movelevel();
X if (Player.p_level > 5.0)
X Timeout = TRUE;
X }
X
X if (Player.p_specialtype == SC_VALAR)
X /* valar */
X Circle = Player.p_level / 5.0;
X
X /* calculate effective quickness */
X dtemp = ((Player.p_gold + Player.p_gems / 2.0) - 1000.0) / Statptr->c_goldtote
X - Player.p_level;;
X dtemp = MAX(0.0, dtemp); /* gold slows player down */
X Player.p_speed = Player.p_quickness + Player.p_quksilver - dtemp;
X
X /* calculate effective strength */
X if (Player.p_poison > 0.0)
X /* poison makes player weaker */
X {
X dtemp = 1.0 - Player.p_poison * Statptr->c_weakness / 800.0;
X dtemp = MAX(0.1, dtemp);
X }
X else
X dtemp = 1.0;
X Player.p_might = dtemp * Player.p_strength + Player.p_sword;
X
X /* insure that important things are within limits */
X Player.p_quksilver = MIN(99.0, Player.p_quksilver);
X Player.p_mana = MIN(Player.p_mana,
X Player.p_level * Statptr->c_maxmana + 1000.0);
X Player.p_brains = MIN(Player.p_brains,
X Player.p_level * Statptr->c_maxbrains + 200.0);
X Player.p_charms = MIN(Player.p_charms, Player.p_level + 10.0);
X
X /*
X * some implementations have problems with floating point compare
X * we work around it with this stuff
X */
X Player.p_gold = floor(Player.p_gold) + 0.1;
X Player.p_gems = floor(Player.p_gems) + 0.1;
X Player.p_mana = floor(Player.p_mana) + 0.1;
X
X if (Player.p_ring.ring_type != R_NONE)
X /* do ring things */
X {
X /* rest to max */
X Player.p_energy = Player.p_maxenergy + Player.p_shield;
X
X if (Player.p_ring.ring_duration <= 0)
X /* clean up expired rings */
X switch (Player.p_ring.ring_type)
X {
X case R_BAD: /* ring drives player crazy */
X Player.p_ring.ring_type = R_SPOILED;
X Player.p_ring.ring_duration = (short) ROLL(10.0, 25.0);
X break;
X
X case R_NAZREG: /* ring disappears */
X Player.p_ring.ring_type = R_NONE;
X break;
X
X case R_SPOILED: /* ring kills player */
X death("A cursed ring");
X break;
X
X case R_DLREG: /* this ring doesn't expire */
X Player.p_ring.ring_duration = 0;
X break;
X }
X }
X
X if (Player.p_age / N_AGE > Player.p_degenerated)
X /* age player slightly */
X {
X ++Player.p_degenerated;
X if (Player.p_quickness > 23.0)
X Player.p_quickness *= 0.99;
X Player.p_strength *= 0.97;
X Player.p_brains *= 0.95;
X Player.p_magiclvl *= 0.97;
X Player.p_maxenergy *= 0.95;
X Player.p_quksilver *= 0.95;
X Player.p_sword *= 0.93;
X Player.p_shield *= 0.93;
X }
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: initplayer()
X/
X/ FUNCTION: initialize a character
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ struct player *playerp - pointer to structure to init
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: floor(), random()
X/
X/ GLOBAL INPUTS: none
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Put a bunch of default values in the given structure.
X/
X/************************************************************************/
X
Xinitplayer(playerp)
Xregister struct player *playerp;
X{
X playerp->p_experience =
X playerp->p_level =
X playerp->p_strength =
X playerp->p_sword =
X playerp->p_might =
X playerp->p_energy =
X playerp->p_maxenergy =
X playerp->p_shield =
X playerp->p_quickness =
X playerp->p_quksilver =
X playerp->p_speed =
X playerp->p_magiclvl =
X playerp->p_mana =
X playerp->p_brains =
X playerp->p_poison =
X playerp->p_gems =
X playerp->p_sin =
X playerp->p_1scratch =
X playerp->p_2scratch = 0.0;
X
X playerp->p_gold = ROLL(50.0, 75.0) + 0.1; /* give some gold */
X
X playerp->p_x = ROLL(-125.0, 251.0);
X playerp->p_y = ROLL(-125.0, 251.0); /* give random x, y */
X
X /* clear ring */
X playerp->p_ring.ring_type = R_NONE;
X playerp->p_ring.ring_duration = 0;
X playerp->p_ring.ring_inuse = FALSE;
X
X playerp->p_age = 0L;
X
X playerp->p_degenerated = 1; /* don't degenerate initially */
X
X playerp->p_type = C_FIGHTER; /* default */
X playerp->p_specialtype = SC_NONE;
X playerp->p_lives =
X playerp->p_crowns =
X playerp->p_charms =
X playerp->p_amulets =
X playerp->p_holywater =
X playerp->p_lastused = 0;
X playerp->p_status = S_NOTUSED;
X playerp->p_tampered = T_OFF;
X playerp->p_istat = I_OFF;
X
X playerp->p_palantir =
X playerp->p_blessing =
X playerp->p_virgin =
X playerp->p_blindness = FALSE;
X
X playerp->p_name[0] =
X playerp->p_password[0] =
X playerp->p_login[0] = '\0';
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: readmessage()
X/
X/ FUNCTION: read message from other players
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: fseek(), fgets(), wmove(), waddstr(), wclrtoeol()
X/
X/ GLOBAL INPUTS: *stdscr, Databuf[], *Messagefp
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ If there is a message from other players, print it.
X/
X/************************************************************************/
X
Xreadmessage()
X{
X move(3, 0);
X clrtoeol();
X fseek(Messagefp, 0L, 0);
X if (fgets(Databuf, SZ_DATABUF, Messagefp) != NULL)
X addstr(Databuf);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: error()
X/
X/ FUNCTION: process evironment error
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ char *whichfile - pointer to name of file which caused error
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: wclear(), cleanup()
X/
X/ GLOBAL INPUTS: errno, *stdscr, printw(), printf(), Windows
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Print message about offending file, and exit.
X/
X/************************************************************************/
X
Xerror(whichfile)
Xchar *whichfile;
X{
Xextern int errno;
Xextern printw(), printf();
Xint (*funcp)();
X
X if (Windows)
X {
X funcp = printw;
X clear();
X }
X else
X funcp = printf;
X
X (*funcp)("An unrecoverable error has occurred reading %s. (errno = %d)\n", whichfile, errno);
X (*funcp)("Please run 'setup' to determine the problem.\n");
X cleanup(TRUE);
X /*NOTREACHED*/
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: distance()
X/
X/ FUNCTION: calculate distance between two points
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ double x1, y1 - x, y coordinates of first point
X/ double x2, y2 - x, y coordinates of second point
X/
X/ RETURN VALUE: distance between the two points
X/
X/ MODULES CALLED: sqrt()
X/
X/ GLOBAL INPUTS: none
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ This function is provided because someone's hypot() library function
X/ fails if x1 == x2 && y1 == y2.
X/
X/************************************************************************/
X
Xdouble
Xdistance(x1, x2, y1, y2)
Xdouble x1, x2, y1, y2;
X{
Xdouble deltax, deltay;
X
X deltax = x1 - x2;
X deltay = y1 - y2;
X return(sqrt(deltax * deltax + deltay * deltay));
X}
X
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: ill_sig()
X/
X/ FUNCTION: exit upon trapping an illegal signal
X/
X/ AUTHOR: E. A. Estes, 12/4/85
X/
X/ ARGUMENTS:
X/ int whichsig - signal which occured to cause jump to here
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: wclear(), printw(), cleanup()
X/
X/ GLOBAL INPUTS: *stdscr
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ When an illegal signal is caught, print a message, and cleanup.
X/
X/************************************************************************/
X
Xill_sig(whichsig)
Xint whichsig;
X{
X clear();
X printw("Error: caught signal # %d.\n", whichsig);
X cleanup(TRUE);
X /*NOTREACHED*/
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: descrstatus()
X/
X/ FUNCTION: return a string describing the player status
X/
X/ AUTHOR: E. A. Estes, 3/3/86
X/
X/ ARGUMENTS:
X/ struct player playerp - pointer to player structure to describe
X/
X/ RETURN VALUE: string describing player's status
X/
X/ MODULES CALLED: none
X/
X/ GLOBAL INPUTS: none
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Return verbal description of player status.
X/ If player status is S_PLAYING, check for low energy and blindness.
X/
X/************************************************************************/
X
Xchar *
Xdescrstatus(playerp)
Xregister struct player *playerp;
X{
X switch (playerp->p_status)
X {
X case S_PLAYING:
X if (playerp->p_energy < 0.2 * (playerp->p_maxenergy + playerp->p_shield))
X return("Low Energy");
X else if (playerp->p_blindness)
X return("Blind");
X else
X return("In game");
X
X case S_CLOAKED:
X return("Cloaked");
X
X case S_INBATTLE:
X return("In Battle");
X
X case S_MONSTER:
X return("Encounter");
X
X case S_TRADING:
X return("Trading");
X
X case S_OFF:
X return("Off");
X
X case S_HUNGUP:
X return("Hung up");
X
X default:
X return("");
X }
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: random()
X/
X/ FUNCTION: return a random floating point number from 0.0 < 1.0
X/
X/ AUTHOR: E. A. Estes, 2/7/86
X/
X/ ARGUMENTS: none
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: rand()
X/
X/ GLOBAL INPUTS: none
X/
X/ GLOBAL OUTPUTS: none
X/
X/ DESCRIPTION:
X/ Convert random integer from library routine into a floating
X/ point number, and divide by the largest possible random number.
X/ We mask large integers with 32767 to handle sites that return
X/ 31 bit random integers.
X/
X/************************************************************************/
X
Xdouble
Xrandom()
X{
X if (sizeof(int) != 2)
X /* use only low bits */
X return((double) (rand() & 0x7fff) / 32768.0);
X else
X return((double) rand() / 32768.0);
X}
X/**/
X/************************************************************************
X/
X/ FUNCTION NAME: collecttaxes()
X/
X/ FUNCTION: collect taxes from current player
X/
X/ AUTHOR: E. A. Estes, 2/7/86
X/
X/ ARGUMENTS:
X/ double gold - amount of gold to tax
X/ double gems - amount of gems to tax
X/
X/ RETURN VALUE: none
X/
X/ MODULES CALLED: fread(), fseek(), fopen(), floor(), fwrite(), fclose()
X/
X/ GLOBAL INPUTS: Player, Goldfile[]
X/
X/ GLOBAL OUTPUTS: Player
X/
X/ DESCRIPTION:
X/ Pay taxes on gold and gems. If the player does not have enough
X/ gold to pay taxes on the added gems, convert some gems to gold.
X/ Add taxes to tax data base; add remaining gold and gems to
X/ player's cache.
X/
X/************************************************************************/
X
Xcollecttaxes(gold, gems)
Xdouble gold;
Xdouble gems;
X{
XFILE *fp; /* to update Goldfile */
Xdouble dtemp; /* for temporary calculations */
Xdouble taxes; /* tax liability */
X
X /* add to cache */
X Player.p_gold += gold;
X Player.p_gems += gems;
X
X /* calculate tax liability */
X taxes = N_TAXAMOUNT / 100.0 * (N_GEMVALUE * gems + gold);
X
X if (Player.p_gold < taxes)
X /* not enough gold to pay taxes, must convert some gems to gold */
X {
X dtemp = floor(taxes / N_GEMVALUE + 1.0); /* number of gems to convert */
X
X if (Player.p_gems >= dtemp)
X /* player has enough to convert */
X {
X Player.p_gems -= dtemp;
X Player.p_gold += dtemp * N_GEMVALUE;
X }
X else
X /* take everything; this should never happen */
X {
X Player.p_gold += Player.p_gems * N_GEMVALUE;
X Player.p_gems = 0.0;
X taxes = Player.p_gold;
X }
X }
X
X Player.p_gold -= taxes;
X
X if ((fp = fopen(Goldfile, "r+")) != NULL)
X /* update taxes */
X {
X dtemp = 0.0;
X fread((char *) &dtemp, sizeof(double), 1, fp);
X dtemp += floor(taxes);
X fseek(fp, 0L, 0);
X fwrite((char *) &dtemp, sizeof(double), 1, fp);
X fclose(fp);
X }
X}
!EOR!
echo x - oldplayer.h
sed 's/^X//' > oldplayer.h << '!EOR!'
X/*
X * oldplayer.h - old player structure
X */
X
Xstruct oldplayer /* player statistics */
X {
X char o_name[21]; /* name */
X char o_password[9]; /* password */
X char o_login[10]; /* login */
X double o_x; /* x coord */
X double o_y; /* y coord */
X double o_experience; /* experience */
X int o_level; /* level */
X short o_quickness; /* quickness */
X double o_strength; /* strength */
X double o_sin; /* sin */
X double o_mana; /* mana */
X double o_gold; /* gold */
X double o_energy; /* energy */
X double o_maxenergy; /* maximum energy */
X double o_magiclvl; /* magic level */
X double o_brains; /* brains */
X short o_crowns; /* crowns */
X struct
X {
X short ring_type; /* type of ring */
X short ring_duration; /* duration of ring */
X } o_ring; /* ring stuff */
X bool o_palantir; /* palantir */
X double o_poison; /* poison */
X short o_holywater; /* holy water */
X short o_amulets; /* amulets */
X bool o_blessing; /* blessing */
X short o_charms; /* charms */
X double o_gems; /* gems */
X short o_quksilver; /* quicksilver */
X double o_sword; /* sword */
X double o_shield; /* shield */
X short o_type; /* character type */
X bool o_virgin; /* virgin */
X short o_lastused; /* day of year last used */
X short o_status; /* playing, cloaked, etc. */
X short o_tampered; /* decree'd, etc. flag */
X double o_1scratch,
X o_2scratch; /* variables used for decree, player battle */
X bool o_blindness; /* blindness */
X int o_notused; /* not used */
X long o_age; /* age in seconds */
X short o_degenerated; /* age/2500 last degenerated */
X short o_istat; /* used for inter-terminal battle */
X#ifdef PHANTPLUS
X short o_lives;
X#endif
X };
!EOR!